package com.leetcode;

/**
 * 345. 反转字符串中的元音字母
 * 双索引指针
 */
public class Solution345 {

    private static char[] vowel = new char[]{'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U'};

    public String reverseVowels(String s) {
        int l = 0;
        int r = s.length() - 1;
        char[] arr = s.toCharArray();
        while (l < r) {
            if (!isVowel(arr[l])) {
                l++;
                continue;
            }
            if (!isVowel(arr[r])) {
                r--;
                continue;
            }
            char tmp = arr[l];
            arr[l] = arr[r];
            arr[r] = tmp;
            l++;
            r--;
        }
        return String.valueOf(arr);
//        return new String(arr);
    }

    private boolean isVowel(char c) {
        if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u'
                || c == 'A' || c == 'E' || c == 'I' || c == 'O' || c == 'U') {
            return true;
        } else {
            return false;
        }
    }

    public boolean isVowel1(char ch) {
        return "aeiouAEIOU".indexOf(ch) >= 0;
    }

    private boolean isVowel2(char ch) {
        for (int i = 0; i < vowel.length; i++) {
            if (vowel[i] == ch) {
                return true;
            }
        }
        return false;
    }
}
